
package calao.client;

import java.util.HashMap;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;

/** Calao desktop client.
 */
public abstract class DesktopFeature 
implements EntryPoint 
{
	
	static HashMap MAP = new HashMap();

	boolean active = false;

	public final void onModuleLoad()
	{
		MAP.put(getName(), this);
	}

	public final Desktop getDesktop()
	{
		return Desktop.getDesktop();
	}

	abstract public String getTitle();

	abstract public String getApplicationName();
	
	/** Activates this feature.
	 * Developers shall override this method to add specific desktop elements associated with this
	 * feature, such as shortcuts or permissions.
	 * @see Desktop#register(Shortcut)
	 * @see Desktop#register(Permission, String, DesktopFeature)
	 */
	public void activate() { }
		
	public final String getName()
	{
		return GWT.getTypeName(this);
	}
	
	static DesktopFeature getFeature(String name)
	{
		return (DesktopFeature)MAP.get(name);
	}
		
	static int count()
	{
		return MAP.size();
	}
	
	public void log(String msg)
	{
		getDesktop().log(getName()+": "+msg);
	}
	
	public void log(Throwable t)
	{
		getDesktop().log(t);
	}

}
